package com.mini.game.bus.userdata;

import com.mini.game.dbbase.IEntity;
import org.hibernate.MappingException;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.id.IdentityGenerator;

import java.io.Serializable;

public class IdOrGenerate extends IdentityGenerator {
    @Override
    public Serializable generate(SharedSessionContractImplementor session, Object object) throws MappingException {
        if (object == null) {
            throw new NullPointerException("object is null");
        }
        return ((IEntity) object).primaryKeyValue();
    }
}
